@extends('layouts.admin')
@section('css')
<link href="{{asset('css/plugins/dataTables/datatables.min.css')}}" rel="stylesheet">
@endsection

@section('content')

<div class="panel panel-default">
    <div class="panel-heading">
        优惠券列表
    </div>
    <div class="panel-body">
        <p class="pull-right">
            @perm('admin.coupon.create')
            <a href="{{route('admin.coupon.create')}}" class="btn btn-primary">创建</a>
            @endperm
        </p>
        <div class="table-responsive">
            {!! $grid->table() !!}
        </div>
    </div>
</div>
@endsection

@section('js')
<script src="{{asset('js/plugins/dataTables/dataTables.min.js')}}"></script>
{!! $html->scripts() !!}

<script>
    $(document).ready(function () {

        $('#dataTableBuilder_wrapper').on('click', '.row-delete', function () {
            var del_url = $(this).data('url')
            var csrf_token = $('meta[name="csrf-token"]').attr('content')
            swal({
                title: '确定删除此项？',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#DD6B55',
                confirmButtonText: '确 定',
                closeOnConfirm: false,
                cancelButtonText: '取 消',
            }, function () {
                $.ajax({
                    method: 'post',
                    url: del_url,
                    data: {
                        _method: 'delete',
                        _token: csrf_token,
                    },
                    success: function (data) {
                        if (typeof data === 'object') {
                            if (data.code == 200) {
                                swal(data.status, '', 'success')
                                window.LaravelDataTables['dataTableBuilder'].ajax.reload()
                            }
                            else {
                                swal(data.message, '', 'error')
                            }
                        }
                    },
                })
            })
        })
    })


</script>
@endsection